using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Medival_Snake
{

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Texture2D DummySightTexture;
        Texture2D HeroTex;
        Texture2D OrcTex;

        Texture2D Alarm;

        public static SpriteFont Font;

        Patrol Orc1Pat;
        Objects Orc1;
        public static Hero Player;
        Tiles LoadTile;
        public static Map Lvl1;

        public string CurrMapName = "testmap";
        

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            graphics.PreferredBackBufferHeight = 480;
            graphics.PreferredBackBufferWidth = 800;
            graphics.ApplyChanges();
        }

        protected override void Initialize()
        {

            base.Initialize();
            
        }

        protected override void LoadContent()
        {

            spriteBatch = new SpriteBatch(GraphicsDevice);

            OrcTex = Content.Load<Texture2D>(@"textures/characters/SingelOrc");
            HeroTex = Content.Load<Texture2D>(@"textures/characters/SingelHero");
            DummySightTexture = Content.Load<Texture2D>(@"textures/characters/yellow");

            Alarm = Content.Load<Texture2D>(@"textures/blink");

            Font = Content.Load<SpriteFont>(@"textures/font");
            
            Player = new Hero(new Vector2(600,200),HeroTex);
            Orc1 = new Objects(new Vector2(500,600), OrcTex,"orc");
            Orc1Pat = new Patrol(Orc1);
            LoadTile = new Tiles();
            LoadTile.TileLoader(Content);
            Lvl1 = new Map();

        }

        protected override void UnloadContent()
        {

        }

        protected override void Update(GameTime gameTime)
        {

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            if (CurrMapName == "testmap")
                Map.fileName = "testmap";

            
           // Orc1Pat.PatrolX(20, 100,gameTime);
            Orc1.Update();
            Lvl1.MapLoader();
            Lvl1.LoadWpLayer();
            Player.Update();

            base.Update(gameTime);
        }


        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();

            Lvl1.Draw(spriteBatch);

            Orc1.Draw(spriteBatch);

            Player.Draw(spriteBatch);

            spriteBatch.Draw(DummySightTexture, Orc1.SightBounds(), new Color(128, 121, 0, 150));

            if (Patrol.chase)
            {
                spriteBatch.DrawString(Font, "boom ur dead", new Vector2(10, 10), Color.White);
                spriteBatch.DrawString(Font, Convert.ToString(Convert.ToInt16(Patrol.ChaseTimer)) , new Vector2(10, 50), Color.White);
            }

            if (Patrol.Alarm)
            {
                spriteBatch.Draw(Alarm,new Rectangle(0,0,800,480),new Color(128,0,0,70));
            }

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
